#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 1010;

int n, m;
struct node
{
	int l, r;
}a[N];
int b[N * 4];
unordered_map<int, int> h;

int main()
{
	cin >> n >> m;
	int cnt = 0;
	for(int i = 1;i <= m;i ++)
	{
		cin >> a[i].l >> a[i].r;
		b[++ cnt] = a[i].l;
		b[++ cnt] = a[i].r;
		b[++ cnt] = a[i].l + 1;
		b[++ cnt] = a[i].r + 1;
	}
	sort(b + 1, b + 1 + cnt);
	cnt = unique(b + 1, b + 1 + cnt) - (b + 1);
	for(int i = 1;i <= cnt;i ++) h[b[i]] = i;

	memset(b, 0 ,sizeof b);
	for(int i = m;i >= 1;i --)
	{
		int l = a[i].l, r = a[i].r;
		int x = h[l], y = h[r];
		for(int j = x;j <= y;j ++) if(!b[j]) b[j] = i;
	}
	int ans = 0;
	set<int> se;
	for(int i = 1;i <= cnt;i ++)
	{
		if(b[i] && !se.count(b[i]))
		{
			ans ++;
			se.insert(b[i]);
		}
	}
	cout << ans << endl;
	return 0;
}